package com.sunl.mall.ali.mq.model;

import com.aliyun.openservices.ons.api.Message;
import com.sunl.mall.common.api.topic.MqTopic;

import java.io.Serializable;

/**
 * 发送时和ali sdk对接的message
 *
 * @date 2020/12/9 10:23
 */
public class RocketMqMessageWrapper<T> extends Message implements Serializable {
    /**
     * 用于临时存放消息体，需要序列化后再放到{@link super#setBody(byte[])}}中
     */
    private RocketMqMessageBody<T> content;

    public RocketMqMessageWrapper() {
    }

    public RocketMqMessageWrapper(MqTopic topic, RocketMqMessageBody<T> content) {
        // body暂时为null，后面会将this.content序列化后再放到body中
        // content.getBusinessId() 存储到 systemProperties(SystemPropKey.KEY, key) 中，但是body中最终也会存储一份bizId，
        // 所以这里会造成业务id被传递了2份，多了几个字节，考虑是否有必要优化。
        super(topic.getTopic(), topic.getExpression(), content.getBusinessId(), null);
        this.content = content;
    }

    public RocketMqMessageBody<T> getContent() {
        return content;
    }

    public void setContent(RocketMqMessageBody<T> content) {
        this.content = content;
    }
}
